package main

import (
	"encoding/json"
	"fmt"
	"math/big"
)

// Base62 字符表
const base62Chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"

// EncodeBase62 把字节数组编码成 Base62 字符串
func EncodeBase62(data []byte) string {
	num := new(big.Int).SetBytes(data)

	if num.Cmp(big.NewInt(0)) == 0 {
		return string(base62Chars[0])
	}

	result := ""
	base := big.NewInt(62)
	rem := new(big.Int)

	for num.Cmp(big.NewInt(0)) > 0 {
		num, rem = new(big.Int).DivMod(num, base, rem)
		result = string(base62Chars[rem.Int64()]) + result
	}

	return result
}

func main() {
	// 你的参数
	params := map[string]string{
		"type":        "form",
		"fileGuid":    "5xkGMEJNDZug4w3X",
		"path":        "/fill",
		"sharingType": "formFill",
	}

	// 1. 序列化为 JSON
	jsonBytes, err := json.Marshal(params)
	if err != nil {
		panic(err)
	}

	// 2. Base62 编码
	encoded := EncodeBase62(jsonBytes)

	fmt.Println("原始 JSON:", string(jsonBytes))
	fmt.Println("Base62 编码:", encoded)
}
